//
//  ZHTabBarController.swift
//  ZHWeibo
//
//  Created by user on 15/12/5.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

class ZHTabBarController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
        /**
         * 不能对一个只读属性赋值,如果对只读属性赋值的话,那么需要使用KVC
        */
        //self.tabBar = ZHTabBarView()
        let customtabBar = ZHTabBarView(frame: self.tabBar.frame)
        //利用KVC赋值
//        self.setValue(customtabBar, forKey: "tabBar")
        setValue(customtabBar, forKeyPath: "tabBar")
        //添加Item
        self.addChildViewController(ZHHomeController(), imageName: "tabbar_home", ItemTitle: "首页")
        self.addChildViewController(ZHMessageController(), imageName: "tabbar_message_center", ItemTitle: "消息")
        self.addChildViewController(ZHDisCoverController(), imageName: "tabbar_discover", ItemTitle: "发现")
        self.addChildViewController(ZHProfileController(), imageName: "tabbar_profile", ItemTitle: "我")
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    }
    //重载构造函数
    private func addChildViewController(childController: UIViewController, imageName: String, ItemTitle: String) {
        childController.title = ItemTitle
        childController.tabBarItem.image = UIImage(named: imageName)
        ///设置图片以原样显示
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.title = ItemTitle
        ///设置文字的颜色-----ZHTabBarView已经设置
        //childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController(ZHNavController(rootViewController: childController))
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
